package com.nativetalk.service.three.search;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.member.TdNtMember;
import com.nativetalk.bean.search.TdNtSearchHistoryList;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.dao.TdNtSearchHisoryDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lizhun on 16/8/24.
 */
@Service
public class SearchServiceImpl implements  SearchService {
    private static Logger logger = Logger.getLogger(SearchServiceImpl.class);
    @Resource
    private TdNtSearchHisoryDao tdNtSearchHisoryDao;
    @Override
    public RetInfo findSearchByMembId(TdNtMember tdNtMember) {
        String logInfo = this.getClass().getName() + ":findSearchByMembId:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {

            if (tdNtMember != null) {
                List<TdNtSearchHistoryList> tdNtSearchHistoryLists = tdNtSearchHisoryDao.findTdNtSearchHistoryList(tdNtMember.getMemb_id());
                if (tdNtSearchHistoryLists != null && tdNtSearchHistoryLists.size() > 0) {
                    retInfo.setMark(ValidationMessages.getValue("MARKYES"));
                    retInfo.setTip("成功");
                    retInfo.setObj(tdNtSearchHistoryLists);
                } else {
                    retInfo.setMark(ValidationMessages.getValue("MARKNO"));
                    retInfo.setTip("暂无搜索记录");
                }

            } else {
                retInfo.setMark(ValidationMessages.getValue("MARKNO"));
                retInfo.setTip("暂无搜索记录");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
